package com.numberone.web.controller.typeList;

import com.numberone.common.annotation.Log;
import com.numberone.common.base.AjaxResult;
import com.numberone.common.enums.BusinessType;
import com.numberone.common.page.TableDataInfo;
import com.numberone.common.utils.poi.ExcelUtil;
import com.numberone.framework.web.base.BaseController;
import com.numberone.system.domain.TypeSecond;
import com.numberone.system.service.ITypeSecondService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 二级类目 信息操作处理
 * 
 * @author numberone
 * @date 2020-09-25
 */
@Controller
@RequestMapping("/system/typeSecond")
public class TypeSecondController extends BaseController
{
    private String prefix = "system/typeSecond";
	
	@Autowired
	private ITypeSecondService typeSecondService;
	
	@RequiresPermissions("system:typeSecond:view")
	@GetMapping()
	public String typeSecond()
	{
	    return prefix + "/typeSecond";
	}
	
	/**
	 * 查询二级类目列表
	 */
	@RequiresPermissions("system:typeSecond:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TypeSecond typeSecond)
	{
		startPage();
        List<TypeSecond> list = typeSecondService.selectTypeSecondList(typeSecond);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出二级类目列表
	 */
	@RequiresPermissions("system:typeSecond:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TypeSecond typeSecond)
    {
    	List<TypeSecond> list = typeSecondService.selectTypeSecondList(typeSecond);
        ExcelUtil<TypeSecond> util = new ExcelUtil<TypeSecond>(TypeSecond.class);
        return util.exportExcel(list, "typeSecond");
    }
	
	/**
	 * 新增二级类目
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存二级类目
	 */
	@RequiresPermissions("system:typeSecond:add")
	@Log(title = "二级类目", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TypeSecond typeSecond)
	{		
		return toAjax(typeSecondService.insertTypeSecond(typeSecond));
	}

	/**
	 * 修改二级类目
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		TypeSecond typeSecond = typeSecondService.selectTypeSecondById(id);
		mmap.put("typeSecond", typeSecond);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存二级类目
	 */
	@RequiresPermissions("system:typeSecond:edit")
	@Log(title = "二级类目", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TypeSecond typeSecond)
	{		
		return toAjax(typeSecondService.updateTypeSecond(typeSecond));
	}
	
	/**
	 * 删除二级类目
	 */
	@RequiresPermissions("system:typeSecond:remove")
	@Log(title = "二级类目", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(typeSecondService.deleteTypeSecondByIds(ids));
	}
	
}
